<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>管理题目</title>
    <meta name="description" content="Charcoal is a free Bootstrap 4 UI kit build by @attacomsian at Wired Dots." />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--Bootstrap 4-->
    <link rel="stylesheet" href="css/bootstrap.css">
    <style>/*  页码样式  */
    ul{
        height:100%;
        list-style-type:none;
    }

    li{
        line-height:20px;
        float:left;
    }

    </style>
    <style>
        .contain {
            width: 500px;
            height: 50px;
            margin: 100px auto;
        }

        .parent {
            width: 100%;
            height: 42px;
            top: 4px;
            position: relative;
        }

        .parent > input:first-of-type {
            /*输入框高度设置为40px, border占据2px，总高度为42px*/
            border-radius: 8px;
            width: 380px;
            height: 43px;
            border: 1px solid #ccc;
            font-size: 16px;
            outline: none;
            margin-right: 20px;
        }

        .parent > input:first-of-type:focus {
            border: 1px solid #317ef3;
            padding-left: 10px;
        }

        .parent > input:last-of-type {
            /*button按钮border并不占据外围大小，设置高度42px*/
            width: 100px;
            height: 44px;
            position: absolute;
            background-color: #5bc0de;
            border: 1px solid #3ed4e8;
            border-radius: 8px;
            color: #fff;
            font-size: 16px;
            outline: none;
        }
        .parent > input:last-of-type:hover{
            background-color: #97d3e7;
        }

        .dropbtn {
            background-color: transparent;
            color: white;
            padding-left: 35px;
            padding-right: 35px;
            font-size: 16px;
            border: none;
            cursor: pointer;
        }

        .dropdown {
            position: relative;
            display: inline-block;
            text-align: center;
        }

        .dropdown-content {
            display: none;
            position: absolute;
            background-color: #f9f9f9;
            width: 100%;;
            box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
        }

        .dropdown-content a {
            color: black;
            padding: 12px 16px;
            text-decoration: none;
            display: block;
        }

        .dropdown-content a:hover {
            background-color: #f1f1f1
        }

        .dropdown:hover .dropdown-content {
            display: block;
        }

        .dropdown:hover .dropbtn {
            background-color: transparent;
        }

        /*导航栏样式*/
        .navbar {
            background-color: #222;
        }
        #daohang {
            list-style-type: none;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: transparent;
        }
        li {
            float: left;
        }
        li a {
            display: block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }
        /*!*鼠标移动到选项上修改背景颜色 *!*/
        /*li a:hover {*/
        /*    background-color: #111;*/
        /*}*/
        /*.active {*/
        /*    background-color: #e83e8c;*/
        /*}*/
        /*下拉框样式*/
        #degree {
            height: 30px;
            font-size: 17px;
            display: inline-block;
            width: 130px;
            position: relative;
            vertical-align: middle;
            padding: 0;
            overflow: hidden;
            background-color: #fff;
            color: #555;
            border: 1px solid #aaa;
            text-shadow: none;
            border-radius: 6px;
            transition: box-shadow 0.25s ease;
            z-index: 2;
        }

        #degree:hover {
            box-shadow: 0 1px 4px rgb(36, 157, 243);
        }

        #degree:before {
            content: "";
            position: absolute;
            width: 0;
            height: 0;
            border: 10px solid transparent;
            border-top-color: #ccc;
            top: 14px;
            right: 10px;
            cursor: pointer;
            z-index: -2;
        }
        #degree select {
            cursor: pointer;
            padding: 10px;
            width: 100%;
            border: none;
            -webkit-appearance: none;
            -moz-appearance: none;
        }
        #degree select:focus {
            outline: none;
        }
    /*    按钮样式*/
        button{
            padding-left: 20px;
            padding-right: 20px;
            padding-top: 5px;
            padding-bottom: 5px;
            color: #fff;
            background-color: #5bc0de;
            border: 0;
            border-radius: 10px;
        }
        button:hover{
            background-color: #97d3e7;
        }
        .even
        {
            background-color: white;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

</head>
<body>

<nav class="navbar navbar-expand-md navbar-dark fixed-top sticky-navigation">
    <a class="navbar-brand font-weight-bold" href="manager.html">我的OJ平台</a>
    <div class="collapse navbar-collapse" id="topMenu">
        <ul class="navbar-nav ml-auto" >
            <div style="margin:5px" id="javaoj">
                <a style="color: white" href="login.html" onclick="logout()"> 退出登录</a>
                <div class="dropdown">
                    <button class="dropbtn">设置</button>
                    <div class="dropdown-content">
                        <a href="updateInfo.html">修改个人信息</a>
                        <a href="updatePassword.html">修改密码</a>
                    </div>
                </div>
            </div>
        </ul>
    </div>
</nav>
<!-- 搜索框 -->
<div class="contain" style="padding-top: 100px">
    <form action="" class="parent">
        <input id="searchText" type="text" placeholder="输入题目名称来查询">
        <input id="searchBtn" type="button" value="搜索" onclick="searchByTitle()">
    </form>
</div>
<section class="my-5 pt-5">
    <div class="container">
        <!-- Tables  -->
        <div class="row mb-5" id="tables">
            <div class="col-sm-12" style="background-color: white">
                <div style="margin-top: 20px">
                    <select id="degree">
                        <option value="default" selected>全部</option>
                        <option value ="简单">简单</option>
                        <option value ="中等">中等</option>
                        <option value="困难">困难</option>
                    </select>&nbsp;&nbsp;
                    <button value="choose" onclick="choose()">筛选</button>&nbsp;&nbsp;
                    <button onclick="findAll()">重置</button>
                </div>
                <div class="mt-3 mb-5">
                    <!--展示题库-->
                    <div><span style="font-size: 22px">题目列表</span> <button onclick="addQuestion()" style="float: right; margin-bottom: 10px">新增题目</button></div>
                    <table class="table table-striped" style="background-color: #f5f5f5">
                    </table>
                </div>
            </div>
        </div>
        <div id="page" align="center">

        </div>
    </div>
</section>
<!--<section class="my-5 pt-5">
    <div class="container">
        &lt;!&ndash; Tables  &ndash;&gt;
        <div class="row mb-5" id="tables">
            <div class="col-sm-12">
                <div class="mt-3 mb-5">
                    <h3>我发布的</h3>
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>标题</th>
                            <th>难度</th>
                            <th></th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody id="problemTable">
                        &lt;!&ndash; The static table rows have been removed &ndash;&gt;
                        </tbody>
                    </table>
                </div>
                <div id="pagination">
                    &lt;!&ndash; The pagination buttons will be added here &ndash;&gt;
                </div>
            </div>
        </div>
    </div>
</section>-->
<!--footer-->
<section class="py-5 bg-dark">
    <div class="container">
        <div class="row">
            <div class="col-md-6 offset-md-3 col-sm-8 offset-sm-2 col-xs-12 text-center">
                <p class="pt-2 text-muted">
                    &copy; by <a href="aboutUs.html" target="_blank">别叫我们组</a>
                </p>

            </div>
        </div>
    </div>
</section>
<script src="js/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://.2/js/bootstrap.min.js"></script>
<script src="js/app.js"></script>
<!--<script>
    var userId=localStorage.getItem("userId");
    var password=localStorage.getItem("password");
    let currentPage = 1;
    const pageSize = 2;

    function getProblem(page, size) {
        $.ajax({
            url: "http://localhost:8020/question/queryQuestionList",
            type: "GET",
            data: {
                page: page,
                size: size,
            },
            success: function (data, status) {
                if (data.code === "200") {
                    makeProblemTable(data.data.content);
                    makePagination(data.data.totalPages);
                } else {
                    console.error("Error fetching questions:", data.msg);
                }
            },
        });
    }

    function makeProblemTable(data) {
        let problemTable = document.querySelector("#problemTable");
        problemTable.innerHTML = ""; // Clear the table
        let index = 1; // 添加一个索引变量
        for (let problem of data) {
            let tr = document.createElement("tr");
            let tdId = document.createElement("td");
            tdId.innerHTML = problem.id;
            tdId.innerHTML = index++;
            tr.appendChild(tdId);
            let tdTitle = document.createElement("td");
            let a = document.createElement("a");
            a.innerHTML = problem.title;
            a.href = "questionDetail.html?id=" + problem.id;
            a.target = '_blank';
            tdTitle.appendChild(a);
            tr.appendChild(tdTitle);
            let tdLevel = document.createElement("td");
            tdLevel.innerHTML = problem.degree || "未知"; // Display "未知" when degree is null.
            tr.appendChild(tdLevel);
            let tdButton = document.createElement("td");
            let button1 = document.createElement("button");
            button1.innerHTML = "删除";
            button1.value = problem.id;
            button1.style = "border-style: none; background-color: transparent;color: #e83e8c";
            button1.onclick = function () {
                if (confirm("确认删除这个题目吗？")) {
                    let body = {
                        id: problem.id,
                    };
                    $.ajax({
                        url: "http://localhost:8010/admin/deleteQuestion",
                        type: "POST",
                        contentType: "application/json",
                        data: JSON.stringify(body),
                        success: function (data, status) {
                            if (data.code === "200") {
                                location.reload();
                            }
                        }
                    });
                }
            };
            tdButton.appendChild(button1);

            let button2 = document.createElement("button");
            button2.innerHTML = "编辑";
            button2.value = problem.id;
            button2.style = "border-style: none; background-color: transparent;color: #e83e8c";
            /*button2.onclick = function () {
                let body = {
                    id: problem.id,
                };
                location.assign("updateQuestion.html");

            };*/
            button2.onclick = function () {
                location.assign("updateQuestion.html?id=" + problem.id);
            };
            tdButton.appendChild(button2);

            tr.appendChild(tdButton);
            problemTable.appendChild(tr);
        }
    }

    /*function makePagination(totalPages) {
        let pagination = document.querySelector("#pagination");
        pagination.innerHTML = ""; // Clear the pagination

        let firstPageBtn = document.createElement("button");
        firstPageBtn.classList.add("page_btn");
        firstPageBtn.innerHTML = "首页";
        firstPageBtn.onclick = function () {
            currentPage = 1;
            getProblem(currentPage, pageSize);
        };
        pagination.appendChild(firstPageBtn);

        let prevPageBtn = document.createElement("button");
        prevPageBtn.classList.add("page_btn");
        prevPageBtn.innerHTML = "上一页";
        prevPageBtn.onclick = function () {
            if (currentPage > 1) {
                currentPage&#45;&#45;;
                getProblem(currentPage, pageSize);
            }
        };
        pagination.appendChild(prevPageBtn);

        for (let i = 1; i <= totalPages; i++) {
            let li = document.createElement("li");
            let button = document.createElement("button");
            button.classList.add("page_btn");
            button.innerHTML = i;
            button.onclick = function () {
                currentPage = i;
                getProblem(currentPage, pageSize);
            };
            li.appendChild(button);
            pagination.appendChild(li);
        }

        let nextPageBtn = document.createElement("button");
        nextPageBtn.classList.add("page_btn");
        nextPageBtn.innerHTML = "下一页";
        nextPageBtn.onclick = function () {
            if (currentPage < totalPages) {
                currentPage++;
                getProblem(currentPage, pageSize);
            }
        };
        pagination.appendChild(nextPageBtn);

        let lastPageBtn = document.createElement("button");
        lastPageBtn.classList.add("page_btn");
        lastPageBtn.innerHTML = "最后一页";
        lastPageBtn.onclick = function () {
            currentPage = totalPages;
            getProblem(currentPage, pageSize);
        };
        pagination.appendChild(lastPageBtn);
    }*/

    /*getProblem(currentPage, pageSize);*/
</script>-->
<script>
    var userId=localStorage.getItem("userId");
    getUser();
    //初始页码为1
    let nowPage=1;
    let totalPages=1;
    $(document).ready(findAll())

    //获取用户登录信息，获取失败则返回登录页面
    /*function getUser() {
        $.ajax({
            url: "admin",
            type: "GET",
            success: function (data, status) {
            }
        })
    }*/

    // 新增题目点击事件
    function addQuestion() {
        window.location.href = "addQuestion.html";
    }

    function autoJudge(btn) {
        let questionId = btn.id;
        $.ajax({
            url:"http://192.168.47.129:8010/admin/autoJudgeQuestion/" + questionId,
            success:function (object) {
                console.log(object);
                let code = object.code;
                if (code == "200") {
                    let array=object.data;
                    localStorage.setItem("scoreList", array);
                    location.assign("score.html");
                }
            }
        })
    }

    function findAll() {
        document.getElementById("degree").selectedIndex = 0;
        $.ajax({
            url:"http://localhost:8020/question/queryQuestionList?page=1",
            success:function (object) {
                console.log(object);
                let code = object.code;
                if (code=="200") {
                    size=object.data.size;
                    totalPages=object.data.totalPages;
                    let pages = "<span><button class='page_btn' href='#' onclick=\"firstPage()\">首页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"previousPage()\" id=\"prePage\">上一页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn'> 第 <span id=\"nowPage\">1</span> / <span id=\"totalPage\">" + totalPages + "</span> 页 </button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"nextPage()\" id=\"nextPage\">下一页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"lastPage()\" id=\"lastPage\">末页</button></span>";
                    $("#page").html(pages);
                    let array=object.data.content;
                    $(".table").html("<tr>\n" +
                        "<th>编号</th>\n" +
                        "<th>标题</th>\n" +
                        "<th>难度</th>\n" +
                        "<th>操作</th>\n" +
                        "</tr>");
                    for (let i=0; i<array.length; i++) {
                        $(".table").append("<tr>\n" +
                            "<td>" + array[i].id + "</td>\n" +
                            "<td><a href='questionDetail.html?questionId=" + array[i].id + "'>" + array[i].title + "</a></td>\n" +
                            "<td>" + array[i].degree + "</td>\n" +
                            "<td><button id='delete-" + array[i].id + "'>删除</button>&nbsp;&nbsp;<button id='edit-" + array[i].id + "'>编辑</button>&nbsp;&nbsp;<button id='autoJudgeQuestion-" + array[i].id + "'>一键判题</button></td>\n" +
                            "</tr>");

                        // 删除功能
                        $("#delete-" + array[i].id).on("click", function () {
                            if (confirm("确认删除这个题目吗？")) {
                                let body = {
                                    id: array[i].id,
                                };
                                $.ajax({
                                    url: "http://192.168.47.129:8010/admin/deleteQuestion",
                                    type: "POST",
                                    contentType: "application/json",
                                    data: JSON.stringify(body),
                                    success: function (data, status) {
                                        if (data.code === "200") {
                                            location.reload();
                                        }
                                    }
                                });
                            }
                        });

                        // 编辑功能
                        $("#edit-" + array[i].id).on("click", function () {
                            location.assign("updateQuestion.html?questionId=" + array[i].id);
                        });
                        $("#autoJudgeQuestion-" + array[i].id).on("click", function () {
                            localStorage.setItem("questionId", array[i].id);
                            location.assign("questionSituation.html");
                        });
                    }
                    //表格单双行变色
                    $().ready(function(){
                        $('tr:even').addClass('even');
                    });
                }
            }
        })
    }


    //跳转到首页的方法
    function firstPage(){
        nowPage=1;
        $.ajax({
            url:"http://localhost:8020/question/queryQuestionList?page="+nowPage,
            //data是返回值 所有数据
            success:function (object) {
                console.log(object);
                let code = object.code;
                if (code=="200") {
                    size=object.data.size;
                    totalPages=object.data.totalPages;
                    let pages = "<span><button class='page_btn' href='#' onclick=\"firstPage()\">首页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"previousPage()\" id=\"prePage\">上一页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn'> 第 <span id=\"nowPage\">1</span> / <span id=\"totalPage\">" + totalPages + "</span> 页 </button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"nextPage()\" id=\"nextPage\">下一页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"lastPage()\" id=\"lastPage\">末页</button></span>";
                    $("#page").html(pages);
                    let array=object.data.content;
                    $(".table").html("<tr>\n" +
                        "<th>编号</th>\n" +
                        "<th>标题</th>\n" +
                        "<th>难度</th>\n" +
                        "<th>操作</th>\n" +
                        "</tr>");
                    for (let i=0; i<array.length; i++) {
                        $(".table").append("<tr>\n" +
                            "<td>" + array[i].id + "</td>\n" +
                            "<td><a href='questionDetail.html?questionId=" + array[i].id + "'>" + array[i].title + "</a></td>\n" +
                            "<td>" + array[i].degree + "</td>\n" +
                            "<td><button id='delete-" + array[i].id + "'>删除</button>&nbsp;&nbsp;<button id='edit-" + array[i].id + "'>编辑</button>&nbsp;&nbsp;<button id='autoJudgeQuestion-" + array[i].id + "'>一键判题</button></td>\n" +
                            "</tr>");

                        // 删除功能
                        $("#delete-" + array[i].id).on("click", function () {
                            if (confirm("确认删除这个题目吗？")) {
                                let body = {
                                    id: array[i].id,
                                };
                                $.ajax({
                                    url: "http://192.168.47.129:8010/admin/deleteQuestion",
                                    type: "POST",
                                    contentType: "application/json",
                                    data: JSON.stringify(body),
                                    success: function (data, status) {
                                        if (data.code === "200") {
                                            location.reload();
                                        }
                                    }
                                });
                            }
                        });

                        // 编辑功能
                        $("#edit-" + array[i].id).on("click", function () {
                            location.assign("updateQuestion.html?questionId=" + array[i].id);
                        });
                        $("#autoJudgeQuestion-" + array[i].id).on("click", function () {
                            localStorage.setItem("questionId", array[i].id);
                            location.assign("questionSituation.html");
                        });
                    }
                    //表格单双行变色
                    $().ready(function(){
                        $('tr:even').addClass('even');
                    });
                }
            }
        })
    }
    //跳转到上一页的方法
    function previousPage() {
        let nowPage = new Number($("#nowPage").text());
        nowPage-=1;
        if(nowPage===0){
            nowPage=1;
            alert("这已经是第一页了");
        }else{
            $.ajax({
                url:"http://localhost:8020/question/queryQuestionList?page="+nowPage,
                //data是返回值 所有数据
                success:function (object) {
                    console.log(object);
                    let code = object.code;
                    if (code=="200") {
                        size=object.data.size;
                        totalPages=object.data.totalPages;
                        let pages = "<span><button class='page_btn' href='#' onclick=\"firstPage()\">首页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"previousPage()\" id=\"prePage\">上一页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn'> 第 <span id=\"nowPage\">" + nowPage + "</span> / <span id=\"totalPage\">" + totalPages + "</span> 页 </button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"nextPage()\" id=\"nextPage\">下一页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"lastPage()\" id=\"lastPage\">末页</button></span>";
                        $("#page").html(pages);
                        let array=object.data.content;
                        $(".table").html("<tr>\n" +
                            "<th>编号</th>\n" +
                            "<th>标题</th>\n" +
                            "<th>难度</th>\n" +
                            "<th>操作</th>\n" +
                            "</tr>");
                        for (let i=0; i<array.length; i++) {
                            $(".table").append("<tr>\n" +
                                "<td>" + array[i].id + "</td>\n" +
                                "<td><a href='questionDetail.html?questionId=" + array[i].id + "'>" + array[i].title + "</a></td>\n" +
                                "<td>" + array[i].degree + "</td>\n" +
                                "<td><button id='delete-" + array[i].id + "'>删除</button>&nbsp;&nbsp;<button id='edit-" + array[i].id + "'>编辑</button>&nbsp;&nbsp;<button id='autoJudgeQuestion-" + array[i].id + "'>一键判题</button></td>\n" +
                                "</tr>");

                            // 删除功能
                            $("#delete-" + array[i].id).on("click", function () {
                                if (confirm("确认删除这个题目吗？")) {
                                    let body = {
                                        id: array[i].id,
                                    };
                                    $.ajax({
                                        url: "http://192.168.47.129:8010/admin/deleteQuestion",
                                        type: "POST",
                                        contentType: "application/json",
                                        data: JSON.stringify(body),
                                        success: function (data, status) {
                                            if (data.code === "200") {
                                                location.reload();
                                            }
                                        }
                                    });
                                }
                            });

                            // 编辑功能
                            $("#edit-" + array[i].id).on("click", function () {
                                location.assign("updateQuestion.html?questionId=" + array[i].id);
                            });
                            $("#autoJudgeQuestion-" + array[i].id).on("click", function () {
                                localStorage.setItem("questionId", array[i].id);
                                location.assign("questionSituation.html");
                            });
                        }
                        //表格单双行变色
                        $().ready(function(){
                            $('tr:even').addClass('even');
                        });
                    }
                }
            })
        }
    }
    //跳转到下一页的方法
    function nextPage() {
        let nowPage = new Number($("#nowPage").text());
        nowPage+=1;
        if(nowPage===totalPages+1){
            nowPage=totalPages;
            alert("这已经是最后一页了");
        }
        $.ajax({
            url:"http://localhost:8020/question/queryQuestionList?page="+nowPage,
            //data是返回值 所有数据
            success:function (object) {
                console.log(object);
                let code = object.code;
                if (code=="200") {
                    size=object.data.size;
                    totalPages=object.data.totalPages;

                    let pages = "<span><button class='page_btn' href='#' onclick=\"firstPage()\">首页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"previousPage()\" id=\"prePage\">上一页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn'> 第 <span id=\"nowPage\">" + nowPage + "</span> / <span id=\"totalPage\">" + totalPages + "</span> 页 </button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"nextPage()\" id=\"nextPage\">下一页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"lastPage()\" id=\"lastPage\">末页</button></span>";
                    $("#page").html(pages);
                    let array=object.data.content;
                    $(".table").html("<tr>\n" +
                        "<th>编号</th>\n" +
                        "<th>标题</th>\n" +
                        "<th>难度</th>\n" +
                        "<th>操作</th>\n" +
                        "</tr>");
                    for (let i=0; i<array.length; i++) {
                        $(".table").append("<tr>\n" +
                            "<td>" + array[i].id + "</td>\n" +
                            "<td><a href='questionDetail.html?questionId=" + array[i].id + "'>" + array[i].title + "</a></td>\n" +
                            "<td>" + array[i].degree + "</td>\n" +
                            "<td><button id='delete-" + array[i].id + "'>删除</button>&nbsp;&nbsp;<button id='edit-" + array[i].id + "'>编辑</button>&nbsp;&nbsp;<button id='autoJudgeQuestion-" + array[i].id + "'>一键判题</button></td>\n" +
                            "</tr>");

                        // 删除功能
                        $("#delete-" + array[i].id).on("click", function () {
                            if (confirm("确认删除这个题目吗？")) {
                                let body = {
                                    id: array[i].id,
                                };
                                $.ajax({
                                    url: "http://192.168.47.129:8010/admin/deleteQuestion",
                                    type: "POST",
                                    contentType: "application/json",
                                    data: JSON.stringify(body),
                                    success: function (data, status) {
                                        if (data.code === "200") {
                                            location.reload();
                                        }
                                    }
                                });
                            }
                        });

                        // 编辑功能
                        $("#edit-" + array[i].id).on("click", function () {
                            location.assign("updateQuestion.html?questionId=" + array[i].id);
                        });
                        $("#autoJudgeQuestion-" + array[i].id).on("click", function () {
                            localStorage.setItem("questionId", array[i].id);
                            location.assign("questionSituation.html");
                        });
                    }
                    //表格单双行变色
                    $().ready(function(){
                        $('tr:even').addClass('even');
                    });
                }
            }
        })
    }
    //跳转到末页的方法
    function lastPage() {
        let nowPage = $("#totalPage").text();
        $.ajax({
            url:"http://localhost:8020/question/queryQuestionList?page="+nowPage,
            //data是返回值 所有数据
            success:function (object) {
                console.log(object);
                let code = object.code;
                if (code=="200") {
                    size=object.data.size;
                    totalPages=object.data.totalPages;
                    let pages = "<span><button class='page_btn' href='#' onclick=\"firstPage()\">首页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"previousPage()\" id=\"prePage\">上一页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn'> 第 <span id=\"nowPage\">" + totalPages + "</span> / <span id=\"totalPage\">" + totalPages + "</span> 页 </button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"nextPage()\" id=\"nextPage\">下一页</button></span>&nbsp;&nbsp;\n" +
                        "<span><button class='page_btn' href='#' onclick=\"lastPage()\" id=\"lastPage\">末页</button></span>";
                    $("#page").html(pages);
                    let array=object.data.content;
                    $(".table").html("<tr>\n" +
                        "<th>编号</th>\n" +
                        "<th>标题</th>\n" +
                        "<th>难度</th>\n" +
                        "<th>操作</th>\n" +
                        "</tr>");
                    for (let i=0; i<array.length; i++) {
                        $(".table").append("<tr>\n" +
                            "<td>" + array[i].id + "</td>\n" +
                            "<td><a href='questionDetail.html?questionId=" + array[i].id + "'>" + array[i].title + "</a></td>\n" +
                            "<td>" + array[i].degree + "</td>\n" +
                            "<td><button id='delete-" + array[i].id + "'>删除</button>&nbsp;&nbsp;<button id='edit-" + array[i].id + "'>编辑</button>&nbsp;&nbsp;<button id='autoJudgeQuestion-" + array[i].id + "'>一键判题</button></td>\n" +
                            "</tr>");

                        // 删除功能
                        $("#delete-" + array[i].id).on("click", function () {
                            if (confirm("确认删除这个题目吗？")) {
                                let body = {
                                    id: array[i].id,
                                };
                                $.ajax({
                                    url: "http://192.168.47.129:8010/admin/deleteQuestion",
                                    type: "POST",
                                    contentType: "application/json",
                                    data: JSON.stringify(body),
                                    success: function (data, status) {
                                        if (data.code === "200") {
                                            location.reload();
                                        }
                                    }
                                });
                            }
                        });

                        // 编辑功能
                        $("#edit-" + array[i].id).on("click", function () {
                            location.assign("updateQuestion.html?questionId=" + array[i].id);
                        });
                        $("#autoJudgeQuestion-" + array[i].id).on("click", function () {
                            localStorage.setItem("questionId", array[i].id);
                            location.assign("questionSituation.html");
                        });
                    }
                    //表格单双行变色
                    $().ready(function(){
                        $('tr:even').addClass('even');
                    });
                }
            }
        })
    }

    // 判断内容是否为空
    function isEmpty(password) {
        if(password === '' || password.trim().length === 0){
            return true;
        }else{
            return false;
        }
    }

    // 搜索框: 根据题目名称模糊搜索
    function searchByTitle() {
        let searchText=document.getElementById("searchText");
        if(isEmpty(searchText.value)){
            alert("搜索内容不能为空！");
            return;
        } else {
            $.ajax({
                url:"http://localhost:8020/question/findTitle/"+searchText.value,
                //data是返回值 所有数据
                success:function (object) {
                    console.log(object);
                    let code = object.code;
                    if (code=="200") {
                        size=object.data.size;
                        totalPages=object.data.totalPages;
                        let pages = "<span><button class='page_btn' href='#' onclick=\"firstPage()\">首页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"previousPage()\" id=\"prePage\">上一页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn'> 第 <span id=\"nowPage\">1</span> / <span id=\"totalPage\">" + totalPages + "</span> 页 </button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"nextPage()\" id=\"nextPage\">下一页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"lastPage()\" id=\"lastPage\">末页</button></span>";
                        $("#page").html(pages);
                        let array=object.data.content;
                        $(".table").html("<tr>\n" +
                            "<th>编号</th>\n" +
                            "<th>标题</th>\n" +
                            "<th>难度</th>\n" +
                            "<th>操作</th>\n" +
                            "</tr>");
                        for (let i=0; i<array.length; i++) {
                            $(".table").append("<tr>\n" +
                                "<td>" + array[i].id + "</td>\n" +
                                "<td><a href='questionDetail.html?questionId=" + array[i].id + "'>" + array[i].title + "</a></td>\n" +
                                "<td>" + array[i].degree + "</td>\n" +
                                "<td><button id='delete-" + array[i].id + "'>删除</button>&nbsp;&nbsp;<button id='edit-" + array[i].id + "'>编辑</button>&nbsp;&nbsp;<button id='autoJudgeQuestion-" + array[i].id + "'>一键判题</button></td>\n" +
                                "</tr>");

                            // 删除功能
                            $("#delete-" + array[i].id).on("click", function () {
                                if (confirm("确认删除这个题目吗？")) {
                                    let body = {
                                        id: array[i].id,
                                    };
                                    $.ajax({
                                        url: "http://localhost:8010/admin/deleteQuestion",
                                        type: "POST",
                                        contentType: "application/json",
                                        data: JSON.stringify(body),
                                        success: function (data, status) {
                                            if (data.code === "200") {
                                                location.reload();
                                            }
                                        }
                                    });
                                }
                            });

                            // 编辑功能
                            $("#edit-" + array[i].id).on("click", function () {
                                location.assign("updateQuestion.html?questionId=" + array[i].id);
                            });
                            $("#autoJudgeQuestion-" + array[i].id).on("click", function () {
                                localStorage.setItem("questionId", array[i].id);
                                location.assign("questionSituation.html");
                            });
                        }
                        //表格单双行变色
                        $().ready(function(){
                            $('tr:even').addClass('even');
                        });
                    } else if (code=="500") {
                        $("#page").html("");
                        $(".table").html("");
                        $(".mt-3").append("<div style='color:red;font-size:20px' align='center'>题库中没有相关题目！</div>");
                    }
                }
            })
        }
    }

    // 筛选
    function choose() {
        let degree = $("#degree").val();
        if (degree=="default") {
            $.ajax({
                url:"http://localhost:8020/question/queryQuestionList/",
                //data是返回值 所有数据
                success:function (object) {
                    console.log(object);
                    let code = object.code;
                    if (code=="200") {
                        size=object.data.size;
                        totalPages=object.data.totalPages;
                        let pages = "<span><button class='page_btn' href='#' onclick=\"firstPage()\">首页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"previousPage()\" id=\"prePage\">上一页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn'> 第 <span id=\"nowPage\">1</span> / <span id=\"totalPage\">" + totalPages + "</span> 页 </button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"nextPage()\" id=\"nextPage\">下一页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"lastPage()\" id=\"lastPage\">末页</button></span>";
                        $("#page").html(pages);
                        let array=object.data.content;
                        $(".table").html("<tr>\n" +
                            "<th>编号</th>\n" +
                            "<th>标题</th>\n" +
                            "<th>难度</th>\n" +
                            "<th>操作</th>\n" +
                            "</tr>");
                        for (let i=0; i<array.length; i++) {
                            $(".table").append("<tr>\n" +
                                "<td>" + array[i].id + "</td>\n" +
                                "<td><a href='questionDetail.html?questionId=" + array[i].id + "'>" + array[i].title + "</a></td>\n" +
                                "<td>" + array[i].degree + "</td>\n" +
                                "<td><button id='delete-" + array[i].id + "'>删除</button>&nbsp;&nbsp;<button id='edit-" + array[i].id + "'>编辑</button>&nbsp;&nbsp;<button id='autoJudgeQuestion-" + array[i].id + "'>一键判题</button></td>\n" +
                                "</tr>");

                            // 删除功能
                            $("#delete-" + array[i].id).on("click", function () {
                                if (confirm("确认删除这个题目吗？")) {
                                    let body = {
                                        id: array[i].id,
                                    };
                                    $.ajax({
                                        url: "http://localhost:8010/admin/deleteQuestion",
                                        type: "POST",
                                        contentType: "application/json",
                                        data: JSON.stringify(body),
                                        success: function (data, status) {
                                            if (data.code === "200") {
                                                location.reload();
                                            }
                                        }
                                    });
                                }
                            });

                            // 编辑功能
                            $("#edit-" + array[i].id).on("click", function () {
                                location.assign("updateQuestion.html?questionId=" + array[i].id);
                            });
                            $("#autoJudgeQuestion-" + array[i].id).on("click", function () {
                                localStorage.setItem("questionId", array[i].id);
                                location.assign("questionSituation.html");
                            });
                        }
                        //表格单双行变色
                        $().ready(function(){
                            $('tr:even').addClass('even');
                        });
                    } else if (code=="500") {
                        $("#page").html("");
                        $(".table").html("");
                        $(".mt-3").append("<div style='color:red;font-size:20px' align='center'>题库中没有相关题目！</div>");
                    }
                }
            })
        } else {
            $.ajax({
                url:"http://localhost:8020/question/findDegree/"+degree,
                //data是返回值 所有数据
                success:function (object) {
                    console.log(object);
                    let code = object.code;
                    if (code=="200") {
                        size=object.data.size;
                        totalPages=object.data.totalPages;
                        let pages = "<span><button class='page_btn' href='#' onclick=\"firstPage()\">首页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"previousPage()\" id=\"prePage\">上一页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn'> 第 <span id=\"nowPage\">1</span> / <span id=\"totalPage\">" + totalPages + "</span> 页 </button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"nextPage()\" id=\"nextPage\">下一页</button></span>&nbsp;&nbsp;\n" +
                            "<span><button class='page_btn' href='#' onclick=\"lastPage()\" id=\"lastPage\">末页</button></span>";
                        $("#page").html(pages);
                        let array=object.data.content;
                        $(".table").html("<tr>\n" +
                            "<th>编号</th>\n" +
                            "<th>标题</th>\n" +
                            "<th>难度</th>\n" +
                            "<th>操作</th>\n" +
                            "</tr>");
                        for (let i=0; i<array.length; i++) {
                            $(".table").append("<tr>\n" +
                                "<td>" + array[i].id + "</td>\n" +
                                "<td><a href='questionDetail.html?questionId=" + array[i].id + "'>" + array[i].title + "</a></td>\n" +
                                "<td>" + array[i].degree + "</td>\n" +
                                "<td><button id='delete-" + array[i].id + "'>删除</button>&nbsp;&nbsp;<button id='edit-" + array[i].id + "'>编辑</button>&nbsp;&nbsp;<button id='autoJudgeQuestion-" + array[i].id + "'>一键判题</button></td>\n" +
                                "</tr>");

                            // 删除功能
                            $("#delete-" + array[i].id).on("click", function () {
                                if (confirm("确认删除这个题目吗？")) {
                                    let body = {
                                        id: array[i].id,
                                    };
                                    $.ajax({
                                        url: "http://localhost:8010/admin/deleteQuestion",
                                        type: "POST",
                                        contentType: "application/json",
                                        data: JSON.stringify(body),
                                        success: function (data, status) {
                                            if (data.code === "200") {
                                                location.reload();
                                            }
                                        }
                                    });
                                }
                            });

                            // 编辑功能
                            $("#edit-" + array[i].id).on("click", function () {
                                location.assign("updateQuestion.html?questionId=" + array[i].id);
                            });
                            $("#autoJudgeQuestion-" + array[i].id).on("click", function () {
                                localStorage.setItem("questionId", array[i].id);
                                location.assign("questionSituation.html");
                            });
                        }
                        //表格单双行变色
                        $().ready(function(){
                            $('tr:even').addClass('even');
                        });
                    } else if (code=="500") {
                        $("#page").html("");
                        $(".table").html("");
                        $(".mt-3").append("<div style='color:red;font-size:20px' align='center'>题库中没有相关题目！</div>");
                    }
                }
            })
        }
    }
    //获取用户登录信息，获取失败则返回登录页面
    /*let userId=localStorage.getItem(userId);*/
    function getUser(){
        if (userId==null){
            location.assign("login.html");
        }
    }
    function logout(){
        localStorage.clear();
    }
    // getUser();
</script>
</body>
</html>
